﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Organizer.ViewModel;
using Organizer.Model;

namespace Organizer
{
    public partial class CategoryListPage : PhoneApplicationPage
    {

        CategoryListPageVM _viewModel;

        public CategoryListPageVM ViewModel
        {
            get { return _viewModel; }
        }

        public CategoryListPage()
        {
            InitializeComponent();

            _viewModel = new CategoryListPageVM();
            DataContext = _viewModel;
        }

        protected void EditCategory()
        {
            //редактирование категории

            if (listBoxCategories.SelectedItem != null)
            {
                string destination = "/CategoryEdit";

                destination += String.Format("?CategoryId={0}", ((Category)listBoxCategories.SelectedItem).Id);
                NavigationService.Navigate(new Uri(destination, UriKind.Relative));
            }
        }

        protected void AddNewCategory()
        {
            //новый таск
            string destination = "/CategoryEdit";
            destination += String.Format("?CategoryId={0}", "null");
            NavigationService.Navigate(new Uri(destination, UriKind.Relative));
        }


        private void appBtnAddCategory_Click(object sender, EventArgs e)
        {
            AddNewCategory();
        }

        private void appBtnDelCategory_Click(object sender, EventArgs e)
        {
            //удалить таск

        }

        private void appBtnEditCategory_Click(object sender, EventArgs e)
        {
            EditCategory();
        }

        private void listBoxCategory_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {

            EditCategory();
        }
    }
}